/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.CustomerSearchCondition;
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.ConnectionManager;
/*    */ import com.newcrm.db.CustomerManager;
/*    */ import com.newcrm.exception.DBException;
/*    */ import com.newcrm.exception.NotFoundException;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintWriter;
/*    */ import java.sql.Connection;
/*    */ import java.sql.SQLException;
/*    */ import java.util.ArrayList;
/*    */ import java.util.List;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.apache.commons.dbutils.DbUtils;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class ListAppCustomers extends AbstractAction
/*    */ {
/* 34 */   private static Logger logger = Logger.getLogger(ListAppCustomers.class
/* 35 */     .getName());
/*    */ 
/*    */   public ListAppCustomers(AbstractHttpServlet servlet)
/*    */   {
/* 38 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException, NotFoundException
/*    */   {
/* 47 */     User user = super.getLoginUser(request);
/* 48 */     CustomerSearchCondition searchCondition = new CustomerSearchCondition(
/* 49 */       request, user, true);
/*    */ 
/* 51 */     int pageSize = 10;
/* 52 */     int offset = Util.getURLIntParameter(request.getParameter("offset"));
/*    */ 
/* 54 */     CustomerManager manager = new CustomerManager();
/*    */ 
/* 56 */     response.setContentType("text/html;charset=utf-8");
/* 57 */     PrintWriter out = response.getWriter();
/* 58 */     JSONObject jsonObject = new JSONObject();
/*    */     try {
/* 60 */       List result = null;
/*    */ 
/* 62 */       Connection conn = ConnectionManager.getInstance().getConnection();
/*    */       try {
/* 64 */         result = manager.getList(conn, searchCondition, offset, 
/* 65 */           pageSize, user, false);
/*    */       } finally {
/*    */         try {
/* 68 */           if (conn != null)
/* 69 */             DbUtils.close(conn);
/*    */         }
/*    */         catch (SQLException e) {
/* 72 */           logger.warn("close conn failed", e);
/*    */         }
/*    */       }
/*    */ 
/* 76 */       if (result == null) {
/* 77 */         result = new ArrayList();
/*    */       }
/*    */ 
/* 80 */       jsonObject.put("error", "0");
/* 81 */       jsonObject.put("customers", result);
/*    */ 
/* 84 */       if (offset == 0) {
/* 85 */         int totalNums = manager.getTotalNum(searchCondition, user);
/* 86 */         jsonObject.put("totalNums", Integer.valueOf(totalNums));
/*    */       }
/*    */     }
/*    */     catch (DBException e) {
/* 90 */       logger.warn("search customer list failed", e);
/* 91 */       jsonObject.put("error", "1");
/* 92 */       jsonObject.put("msg", "客户一览加载失败");
/*    */     }
/* 94 */     out.println(jsonObject);
/* 95 */     out.flush();
/* 96 */     out.close();
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ListAppCustomers
 * JD-Core Version:    0.6.1
 */